package hash表;

import java.util.HashMap;
import java.util.Map;

public class Solution383 {
    public static void main(String[] args) {
        System.out.println(canConstruct("aa", "ab"));
    }

    public static boolean canConstruct(String ransomNote, String magazine) {
        char[] array1 = ransomNote.toCharArray();
        char[] array2 = magazine.toCharArray();

        Map<Character, Integer> map = new HashMap<>();
        for (char a : array2)
            if (map.containsKey(a)) {
                map.put(a, map.get(a) + 1);
            } else {
                map.put(a, 1);
            }

        for (char b : array1) {
            Integer size = map.get(b);
            if (!map.containsKey(b) || size == 0) {
                return false;
            }
            map.put(b, size - 1);
        }
        return true;
    }


}
